package fileget;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import util.Bean;

public class FileProvider implements PersonProvider{
	private File file;
	public FileProvider(File file){
		this.file=file;
	}
	@Override
	public List getPersonList() {
		// TODO Auto-generated method stub
		List<Bean> list=new ArrayList<>();
		try {
			String result;
			String[] results;
			Bean b;
			InputStream stream=new FileInputStream(file);
			BufferedInputStream bis=new BufferedInputStream(stream);
			InputStreamReader itr=new InputStreamReader(bis);
			BufferedReader br=new BufferedReader(itr);
			while((result=br.readLine())!=null){
				results=new String[result.length()];
				result=result.replaceAll("\"", "");
				results=result.split(",");	
				b=new Bean();
				b.inputByCount(results);
				list.add(b);
			}
			br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}


}
